<template>
	<div class="app-container">
		<el-tabs v-model="activeName" type="card" @tab-click="handleClick">
			<el-tab-pane label="公众号配置" name="first">
				<el-form :rules="rules" label-width="150px">
					<el-form-item :label="item.name" prop="value" v-for="item in applicationConfigList.slice(0,2)"
						:key="item.id">
						<el-input v-model="item.value" placeholder="请输入value" class="elInput" />
					</el-form-item>
				</el-form>

			</el-tab-pane>
			<el-tab-pane label="用户端配置" name="second">
				<el-form :rules="rules" label-width="150px">
					<el-form-item :label="item.name" prop="value" v-for="item in applicationConfigList.slice(2,7)"
						:key="item.id">
						<el-input v-model="item.value" placeholder="请输入value" class="elInput" />
					</el-form-item>
				</el-form>
			</el-tab-pane>
			<el-tab-pane label="技师端配置" name="third">
				<el-form :rules="rules" label-width="150px">
					<el-form-item :label="item.name" prop="value" v-for="item in applicationConfigList.slice(7,12)"
						:key="item.id">
						<el-input v-model="item.value" placeholder="请输入value" class="elInput" />
					</el-form-item>
				</el-form>
			</el-tab-pane>
		</el-tabs>
		<el-button type="primary" size="medium" @click="submitForm">提 交</el-button>


		<!-- <el-table v-loading="loading" :data="applicationConfigList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="ID" align="center" prop="id" />
			<el-table-column label="name" align="center" prop="name" />
			<el-table-column label="value" align="center" prop="value" />
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
						v-hasPermi="['applicationConfig:applicationConfig:edit']">修改</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
						v-hasPermi="['applicationConfig:applicationConfig:remove']">删除</el-button>
				</template>
			</el-table-column>
		</el-table> -->

		<!-- <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
			@pagination="getList" /> -->

		<!-- 添加或修改应用配置对话框 -->
		<!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="name" prop="name">
          <el-input v-model="form.name" placeholder="请输入name" />
        </el-form-item>
        <el-form-item label="value" prop="value">
          <el-input v-model="form.value" placeholder="请输入value" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
	</div>
</template>

<script>
	import {
		listApplicationConfig,
		getApplicationConfig,
		delApplicationConfig,
		addApplicationConfig,
		updateApplicationConfig,
		updateConfig
	} from "@/api/applicationConfig/applicationConfig";

	export default {
		name: "ApplicationConfig",
		data() {
			return {
				activeName: 'first',
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 应用配置表格数据
				applicationConfigList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 20,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询应用配置列表 */
			getList() {
				this.loading = true;
				listApplicationConfig(this.queryParams).then(response => {
					this.applicationConfigList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},

			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					id: null,
					name: null,
					code: null,
					value: null,
					isDelete: null,
					updateTime: null,
					createTime: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.id)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.reset();
				this.open = true;
				this.title = "添加应用配置";
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const id = row.id || this.ids
				getApplicationConfig(id).then(response => {
					this.form = response.data;
					this.open = true;
					this.title = "修改应用配置";
				});
			},
			/** 提交按钮 */
			submitForm() {
				updateConfig(this.applicationConfigList).then(response => {
					this.$modal.msgSuccess("提交成功");
					this.open = false;
					this.getList();
				});
				// this.$refs["form"].validate(valid => {
				// 	if (valid) {
				// 		if (this.form.id != null) {
				// 			updateApplicationConfig(this.form).then(response => {
				// 				this.$modal.msgSuccess("修改成功");
				// 				this.open = false;
				// 				this.getList();
				// 			});
				// 		} else {
				// 			addApplicationConfig(this.form).then(response => {
				// 				this.$modal.msgSuccess("新增成功");
				// 				this.open = false;
				// 				this.getList();
				// 			});
				// 		}
				// 	}
				// });
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const ids = row.id || this.ids;
				this.$modal.confirm('是否确认删除应用配置编号为"' + ids + '"的数据项？').then(function() {
					return delApplicationConfig(ids);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			// 标签点击
			handleClick(tab, event) {
				this.activeName = tab.name
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('applicationConfig/applicationConfig/export', {
					...this.queryParams
				}, `applicationConfig_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>